package com.vxb.testmvp.test_zonghe.test_2;

import android.content.Context;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.holenzhou.pullrecyclerview.BaseRecyclerAdapter;
import com.holenzhou.pullrecyclerview.BaseViewHolder;
import com.vxb.testmvp.R;
import com.vxb.testmvp.test_zonghe.entity.ZhuangEntity;
import com.vxb.testmvp.util.Util;

import java.util.List;

import static com.vxb.testmvp.R.id.image;

/**
 * Created by User on 2017/3/31.
 */

public class TestTowAdapter extends BaseRecyclerAdapter<ZhuangEntity> {

    private Context context;

    public TestTowAdapter(Context context, int layoutResId, List<ZhuangEntity> data) {
        super(context, layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(final BaseViewHolder holder, final ZhuangEntity item) {


        Glide.with(holder.itemView.getContext())
                .load(item.getImage_url())
                .placeholder(R.drawable.zhanweitu)// 占位图
                .error(R.drawable.error)//错误图
                .diskCacheStrategy(DiskCacheStrategy.NONE)//不缓存
                .into((ImageView) holder.getView(R.id.imageIv));

        ((TextView) holder.getView(R.id.descriptionTv)).setText(item.getDescription());

        holder.getView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (view.getId()) {
                    case R.id.imageIv:
                        Util.showToast(context, item.getImage_url());
                        break;
                    case R.id.descriptionTv:
                        Util.showToast(context, item.getDescription());
                        break;
                }

            }
        });
    }
}